package cmd

import (
	"github.com/spf13/cobra"
	"kf/router"
	"kf/wirex"
)

var configPath string

func init() {
	serverCmd.PersistentFlags().StringVar(&configPath, "config", "config/config.yaml", "config file")
	serverCmd.PersistentFlags().StringVarP(&router.Port, "port", "p", "8081", "监听端口号")
	serverCmd.PersistentFlags().BoolVarP(&router.Daemon, "daemon", "d", false, "是否为守护进程模式")
}

var serverCmd = &cobra.Command{
	Use:     "server",
	Short:   "启动http服务",
	Example: "go-fly Server -c config/",
	Run: func(cmd *cobra.Command, args []string) {
		initialize, _, err := wirex.Initialize(configPath)
		if err != nil {
			panic("启动失败")
		}
		server := initialize.Server
		server.Run()
	},
}
